package net.gzw1993.runmate.activity;

import android.content.Intent;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import net.gzw1993.runmate.R;

public class StartSportActivity extends AppCompatActivity {

    @ViewInject(R.id.animotion_text)
    private TextView myanimotion;
    private Animation animotion;
    private String[] text = {"2","1"};
    private boolean isend = false;
    private int i = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start_sport);
        ViewUtils.inject(this,this);
        initView();
    }

    private void initView() {
        getForAnimation();


        animotion.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                i++;
                if(i == 1){
                    myanimotion.setText("2");
                    initView();
                }else if(i == 2){
                    myanimotion.setText("1");
                    initView();
                }else if(i == 3){
                    myanimotion.setText("GO");
                    getGoAnimotion();
                    animotion.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            Intent intent = new Intent(StartSportActivity.this,RuningActivity.class);
                            startActivity(intent);
                            finish();
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }
                    });
                }

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }
    public void getGoAnimotion(){
        animotion = AnimationUtils.loadAnimation(this,R.anim.goscale);
        myanimotion.startAnimation(animotion);
    }

    public void getForAnimation(){
        animotion = AnimationUtils.loadAnimation(this,R.anim.scale);
        myanimotion.startAnimation(animotion);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_start_sport, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
